package uilayer;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.TileObserver;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import modellayer.Ansat;
import ctrlayer.OrdreCtr;

public class OrdreGUI extends JFrame {

	private OrdreCtr oCtr;
	private MainMenuGUI mGUI;
	private PersonGUI pGUI;

	private JPanel contentPane;
	private static OrdreGUI frame;
	private JTextField txtOrdreNr;
	private JTextField txtNyStatus;
	private JLabel lblVisDato;
	private JLabel lblVisPris;
	private JLabel lblVisStatus;
	private JLabel lblNyOrdreNr;
	private JLabel lblNyDato;
	private JLabel lblNyPris;
	private JLabel lblNyStatus;
	private JButton bFindVare;
	private JButton btilfjVareTil;
	private JButton bAfslutOrdre;
	private JPanel panel;
	private JButton bSoeg;
	private JButton bSletOrdre;
	private JLabel lblVisOrdreNr;
	private JLabel lblOrdreNr;
	private JButton bRedigerAntalVare;
	private JButton bFjernVareP;
	private JButton bRedigerStatus;
	private JTextField txtTlf;
	private JTextField txtDato;
	private JTextField txtStatus;
	private JButton bTilfoej;
	private JCheckBox cbTilbud;
	private JCheckBox cbOrdre;
	private JLabel lblTlf;
	private JLabel lblTilbud;
	private JLabel lblOrdre;
	private JLabel lblDato;
	private JLabel lblStatus;
	private JLabel lblOrdreNotFound;
	private JButton bKundeinfo;
	private DefaultTableModel model;
	private JTable table;
	private JScrollPane scrollPane;
	private JButton bFindOrdre;
	private Ansat bruger;
	private JButton btilfjOrdre;
	private JButton bLoad;
	private JButton bSave;
	private JButton bTilbage;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() 
		{
			public void run() 
			{
				try 
				{
					frame = new OrdreGUI();
					frame.setVisible(true);
				} catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public OrdreGUI() {
		oCtr = new OrdreCtr();
		pGUI = new PersonGUI();
		if(pGUI.getBruger() == null)
		{
			pGUI.setBruger(pGUI.findAnsat(1));
			bruger = pGUI.getBruger();
		}
		else
		{
			bruger = pGUI.getBruger();
		}
		setTitle("Ordre menu - logget ind som " + bruger.getNavn());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1720, 880);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		btilfjOrdre = new JButton("Tilf\u00F8j ordre");
		btilfjOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btilfjOrdre.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				addOrdreScreen();
				paint();
			}
		});
		btilfjOrdre.setBounds(10, 20, 150, 40);
		contentPane.add(btilfjOrdre);

		bFindOrdre = new JButton("Find ordre");
		bFindOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bFindOrdre.addActionListener(new ActionListener() 
		{

			public void actionPerformed(ActionEvent arg0) 
			{
				findOrdreScreen();
				paint();
			}
		});
		bFindOrdre.setBounds(10, 70, 150, 40);
		contentPane.add(bFindOrdre);

//		bSave = new JButton("Save");
//		bSave.setFont(new Font("Tahoma", Font.PLAIN, 16));
//		bSave.setBounds(10, 170, 150, 40);
//		contentPane.add(bSave);

		bTilbage = new JButton("Tilbage");
		bTilbage.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bTilbage.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				save();
				frame.dispose();
				mGUI.main(null);
			}
		});
		bTilbage.setBounds(10, 270, 150, 40);
		contentPane.add(bTilbage);

//		bLoad = new JButton("Load");
//		bLoad.setFont(new Font("Tahoma", Font.PLAIN, 16));
//		bLoad.setBounds(10, 220, 150, 40);
//		contentPane.add(bLoad);

		panel = new JPanel();
		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		panel.setBounds(172, 20, 1520, 800);
		contentPane.add(panel);
		panel.setLayout(null);



		lblOrdre = new JLabel("Ordre:");
		lblOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblOrdre.setBounds(10, 71, 70, 16);

		lblDato = new JLabel("Dato:");
		lblDato.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblDato.setBounds(10, 100, 70, 16);

		lblStatus = new JLabel("Status:");
		lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblStatus.setBounds(10, 129, 70, 16);

		txtTlf = new JTextField();
		txtTlf.setBounds(90, 11, 116, 22);
		txtTlf.setColumns(10);

		txtDato = new JTextField();
		txtDato.setBounds(90, 98, 116, 22);
		txtDato.setColumns(10);

		txtStatus = new JTextField();
		txtStatus.setBounds(90, 127, 116, 22);
		txtStatus.setColumns(10);

		cbOrdre = new JCheckBox("Hvis Ordre");
		cbOrdre.setBounds(90, 68, 113, 25);

		cbTilbud = new JCheckBox("Hvis Tilbud");
		cbTilbud.setBounds(90, 39, 113, 25);

		bTilfoej = new JButton("Tilf\u00F8j");
		bTilfoej.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				if(!txtTlf.getText().equals("") || !txtDato.getText().equals("") || !txtStatus.getText().equals(""))
				{
					oCtr.createOrdre(txtTlf.getText(), cbTilbud.isSelected(), cbOrdre.isSelected(), txtDato.getText(), txtStatus.getText(), 0);
				}
				//addScreenreset();
				paint();
			}
		});
		bTilfoej.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bTilfoej.setBounds(10, 166, 150, 40);

		lblOrdreNr = new JLabel("Ordre Nr");
		lblOrdreNr.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblOrdreNr.setBounds(10, 26, 70, 16);

		txtOrdreNr = new JTextField();
		txtOrdreNr.addKeyListener(new KeyAdapter() 
		{
			@Override
			public void keyTyped(KeyEvent arg0) 
			{
				char c = arg0.getKeyChar();
				if(!Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)
				{
					arg0.consume();
				}
			}
		});
		txtOrdreNr.setBounds(95, 20, 150, 22);
		txtOrdreNr.setColumns(10);

		bSoeg = new JButton("S\u00F8g");
		bSoeg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(!txtOrdreNr.getText().equals(""))
				{
					lblNyOrdreNr.setText(txtOrdreNr.getText());
					lblNyDato.setText(oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getDato());
					double tempValue = oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getTotalPris();
					lblNyPris.setText(Double.toString(tempValue));
					lblNyStatus.setText(oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getStatus());
					if(txtOrdreNr.getText().equals("") || oCtr.findOrdre(Integer.parseInt(txtOrdreNr.getText())) == null)
					{
						lblOrdreNotFound.setVisible(true);
					}
					else
					{
						ordreScreen();
					}
				}
				paint();

			}
		});
		bSoeg.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bSoeg.setBounds(10, 55, 150, 40);

		/**
		 * tabel til find vare
		 */		
		scrollPane = new JScrollPane();
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane.setBounds(777, 13, 731, 774);

		model = new DefaultTableModel(new Object[][] {}, new String[] { "VareID", "Navn", "Beskrivelse", "Pris", "Stregkode", "Antal", "V\u00E6lg"});

		table = new JTable(model)
		{
			Class[] columnTypes = new Class[] {
					Integer.class, String.class, String.class, Double.class, Integer.class, Integer.class, Boolean.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		};
		table.setFont(new Font("Tahoma", Font.PLAIN, 16));
		table.setRowHeight(20);
		table.getTableHeader().setFont(new Font("Tahoma", Font.PLAIN, 16));

		scrollPane.setViewportView(table);	

		DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();		
		rightRenderer.setHorizontalAlignment(SwingConstants.CENTER);
		for(int i = 0; i < table.getColumnCount(); i++)
		{
			table.getColumnModel().getColumn(i).setCellRenderer(rightRenderer);
		}

		lblVisOrdreNr = new JLabel("Ordre nr:");
		lblVisOrdreNr.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblVisOrdreNr.setBounds(10, 170, 70, 16);

		lblOrdreNotFound = new JLabel("Ordren blev ikke fundet!");
		lblOrdreNotFound.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblOrdreNotFound.setBounds(10, 120, 177, 16);

		lblVisDato = new JLabel("Dato:");
		lblVisDato.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblVisDato.setBounds(10, 199, 70, 16);

		lblVisPris = new JLabel("Totalpris:");
		lblVisPris.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblVisPris.setBounds(10, 228, 70, 16);

		lblVisStatus = new JLabel("Status:");
		lblVisStatus.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblVisStatus.setBounds(10, 257, 70, 16);

		lblNyOrdreNr = new JLabel("New label");
		lblNyOrdreNr.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNyOrdreNr.setBounds(165, 170, 70, 16);

		lblNyDato = new JLabel("New label");
		lblNyDato.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNyDato.setBounds(165, 199, 70, 16);

		lblNyPris = new JLabel("New label");
		lblNyPris.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNyPris.setBounds(165, 228, 70, 16);

		lblNyStatus = new JLabel("New label");
		lblNyStatus.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNyStatus.setBounds(165, 257, 70, 16);

		lblTlf = new JLabel("Telefon:");
		lblTlf.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblTlf.setBounds(10, 13, 70, 16);

		lblTilbud = new JLabel("Tilbud:");
		lblTilbud.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblTilbud.setBounds(10, 42, 70, 16);

		lblOrdre = new JLabel("Ordre:");
		lblOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblOrdre.setBounds(10, 71, 70, 16);

		lblDato = new JLabel("Dato:");
		lblDato.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblDato.setBounds(10, 100, 70, 16);

		lblStatus = new JLabel("Status:");
		lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblStatus.setBounds(10, 129, 70, 16);

		txtTlf = new JTextField();
		txtTlf.setBounds(90, 11, 116, 22);
		txtTlf.setColumns(10);

		txtDato = new JTextField();
		txtDato.setBounds(90, 98, 116, 22);
		txtDato.setColumns(10);

		txtStatus = new JTextField();
		txtStatus.setBounds(90, 127, 116, 22);
		txtStatus.setColumns(10);

		cbOrdre = new JCheckBox("Hvis Ordre");
		cbOrdre.setBounds(90, 68, 113, 25);

		cbTilbud = new JCheckBox("Hvis Tilbud");
		cbTilbud.setBounds(90, 39, 113, 25);

		bTilfoej = new JButton("Tilf\u00F8j");
		bTilfoej.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				if(!txtTlf.getText().equals("") || !txtDato.getText().equals("") || !txtStatus.getText().equals(""))
				{
					oCtr.createOrdre(txtTlf.getText(), cbTilbud.isSelected(), cbOrdre.isSelected(), txtDato.getText(), txtStatus.getText(), 0);
				}
				txtTlf.setText("");
				txtDato.setText("");
				cbTilbud.setSelected(false);
				cbOrdre.setSelected(false);
				txtStatus.setText("");
				paint();
				//updateLblInfo();
			}
		});
		bTilfoej.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bTilfoej.setBounds(10, 166, 150, 40);

		bFindVare = new JButton("Find vare");
		bFindVare.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				tableRemoveRows(model.getRowCount());
				generateListVare();
			}
		});
		bFindVare.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bFindVare.setBounds(10, 315, 150, 40);

		btilfjVareTil = new JButton("Tilf\u00F8j vare");
		btilfjVareTil.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				addVareTilOrdre();
				paint();
				updateLblInfo();
			}
		});
		btilfjVareTil.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btilfjVareTil.setBounds(375, 315, 150, 40);

		bRedigerAntalVare = new JButton("Rediger antal");
		bRedigerAntalVare.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				redigerAntal();
				paint();
				updateLblInfo();

			}
		});
		bRedigerAntalVare.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bRedigerAntalVare.setBounds(195, 315, 150, 40);

		bFjernVareP = new JButton("Fjern vare");
		bFjernVareP.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				fjernVare();
				paint();
				updateLblInfo();
			}
		});
		bFjernVareP.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bFjernVareP.setBounds(10, 368, 150, 40);

		bRedigerStatus = new JButton("Rediger status");
		bRedigerStatus.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				redigerStatus();
				paint();
				updateLblInfo();
			}
		});
		bRedigerStatus.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bRedigerStatus.setBounds(375, 245, 150, 40);

		bAfslutOrdre = new JButton("Afslut ordre");
		bAfslutOrdre.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				oCtr.afslutOrdre(Integer.parseInt(txtOrdreNr.getText()));
				paint();
				updateLblInfo();
			}
		});
		bAfslutOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bAfslutOrdre.setBounds(195, 368, 150, 40);

		bSletOrdre = new JButton("Slet ordre");
		bSletOrdre.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				sletOrdre();
				paint();
			}
		});
		bSletOrdre.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bSletOrdre.setBounds(375, 368, 150, 40);

		txtNyStatus = new JTextField();
		txtNyStatus.setBounds(247, 255, 116, 22);
		txtNyStatus.setColumns(10);

		bKundeinfo = new JButton("Kundeinfo");
		bKundeinfo.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				String Kundeoplysninger = "<html>Navn: " + oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getNavn() +
						"<br>Adresse: " + oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getAdresse() + "<br>Postnummer: " +
						oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getPostnr() + "<br>By: " + 
						oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getBy() + "<br>Telefon: " +
						oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getTlf() + "<br>Email: " +
						oCtr.findKundeOrdreNr(Integer.parseInt(lblNyOrdreNr.getText())).getEmail();
				JLabel label = new JLabel(Kundeoplysninger);
				label.setFont(new Font("Tahoma", Font.PLAIN, 16));
				JOptionPane.showMessageDialog(null, label, "Kundeinformation", JOptionPane.INFORMATION_MESSAGE);

			}
		});
		bKundeinfo.setFont(new Font("Tahoma", Font.PLAIN, 16));
		bKundeinfo.setBounds(10, 421, 150, 40);

		/*
		panel.add(lblOrdreNr);
		panel.add(txtOrdreNr);
		panel.add(bS¯g);
		panel.add(lblVisOrdreNr);
		panel.add(lblVisDato);
		panel.add(lblVisPris);
		panel.add(lblVisStatus);
		panel.add(lblNyOrdreNr);
		panel.add(lblNyDato);
		panel.add(lblNyPris);
		panel.add(lblNyStatus);
		panel.add(bFindVare);
		panel.add(btilfjVareTil);
		panel.add(bRedigerAntalVare);
		panel.add(bFjernVareP);
		panel.add(bRedigerStatus);
		panel.add(bSletOrdre);
		panel.add(txtNyStatus);
		panel.add(bAfslutOrdre);
		panel.add(scrollPane);

		panel.add(lblOrdreNr);
		panel.add(txtOrdreNr);
		panel.add(bS¯g);
		panel.add(lblOrdreNotFound);
		 */
		

	}

	public void paint()
	{
		panel.revalidate();
		panel.repaint();
	}

	public void tableRemoveRows(int rowCount)
	{
		for (int i = rowCount - 1; i >= 0; i--) 
		{
			model.removeRow(i);
		}
	}

	public void generateAlleVare()
	{
		int i = 0;
		int lastID = oCtr.getVareList().get(oCtr.getVareList().size()-1).getVareID();

		while(i <= lastID)
		{
			if(oCtr.findVare(i) != null)
			{
				model.addRow(new Object[]{oCtr.findVare(i).getVareID(), oCtr.findVare(i).getNavn(), oCtr.findVare(i).getBeskrivelse(), oCtr.findVare(i).getPris(), oCtr.findVare(i).getStregkode(), 0, false });
				i++;
			}
			else
			{
				i++;
			}
		}
		scrollPane.setVisible(true);
	}

	public void generateListVare()
	{
		int i = 0;
		int lastID = oCtr.getVareList().get(oCtr.getVareList().size()-1).getVareID();

		while(i <= lastID)
		{	
			if(oCtr.findVare(i) != null)
			{
				model.addRow(new Object[]
						{
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getVareID(),
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getNavn(), 
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getBeskrivelse(), 
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getPris(), 
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getStregkode(), 
						oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getVList().get(i).getBeholdning(), false
						});
				i++;
			}
			else
			{
				i++;
			}
		}
	
	}

	public void updateLblInfo()
	{
//		lblNyOrdreNr.setText(txtOrdreNr.getText());
		lblNyDato.setText(oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getDato());
		double tempValue = oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getTotalPris();
		lblNyPris.setText(Double.toString(tempValue));
		lblNyStatus.setText(oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).getStatus());
	}

	public void ordreScreen()
	{
		panel.add(lblVisOrdreNr);
		panel.add(lblVisDato);
		panel.add(lblVisPris);
		panel.add(lblVisStatus);
		panel.add(lblNyOrdreNr);
		panel.add(lblNyDato);
		panel.add(lblNyPris);
		panel.add(lblNyStatus);
		panel.add(bFindVare);
		panel.add(btilfjVareTil);
		panel.add(bRedigerAntalVare);
		panel.add(bFjernVareP);
		panel.add(bRedigerStatus);
		panel.add(bSletOrdre);
		panel.add(txtNyStatus);
		panel.add(bAfslutOrdre);
		panel.add(bKundeinfo);
		txtOrdreNr.setText("");
		panel.add(scrollPane);
		tableRemoveRows(model.getRowCount());			
		generateAlleVare();
	}

	public void findOrdreScreen()
	{
		panel.removeAll();
		panel.add(lblOrdreNr);
		panel.add(txtOrdreNr);
		panel.add(bSoeg);
		panel.add(lblOrdreNotFound);
		lblOrdreNotFound.setVisible(false);
	}

	public void addOrdreScreen()
	{
		panel.removeAll();
		panel.add(lblTlf);
		panel.add(lblTilbud);
		panel.add(lblOrdre);
		panel.add(lblDato);
		panel.add(lblStatus);
		panel.add(txtTlf);
		panel.add(txtDato);
		panel.add(txtStatus);
		panel.add(cbOrdre);
		panel.add(cbTilbud);
		panel.add(bTilfoej);
	}

	//	public void addScreenreset()
	//	{
	//		txtTlf.setText("");
	//		txtDato.setText("");
	//		cbTilbud.setSelected(false);
	//		cbOrdre.setSelected(false);
	//		txtStatus.setText("");
	//	}

	public void redigerAntal()
	{
		for(int i = 0; i < oCtr.getVareList().size(); i++)
		{
			int temp = (int)table.getModel().getValueAt(i, table.getModel().getColumnCount() - 2);
			oCtr.findVarePåListe(Integer.parseInt(lblNyOrdreNr.getText()), (int)table.getModel().getValueAt(i, 0)).setBeholdning(temp);
			double tempPris =+ oCtr.getVareList().get(i).getBeholdning() * oCtr.getVareList().get(i).getPris();
			oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).setTotalPris(tempPris);
		}
	}

	public void fjernVare()
	{
		for(int i = 0; i < oCtr.getVareList().size(); i++)
		{
			if((boolean)table.getModel().getValueAt(i, table.getModel().getColumnCount() - 1))
			{
				oCtr.deleteVareFraListe(Integer.parseInt(lblNyOrdreNr.getText()), (int)table.getModel().getValueAt(i, 0));
			}
		}
	}

	public void redigerStatus()
	{
		if(txtNyStatus.getText().equals(""))
		{
			lblNyStatus.setText(txtNyStatus.getText());
			oCtr.findOrdre(Integer.parseInt(lblNyOrdreNr.getText())).setStatus(txtNyStatus.getText());
		}
		txtNyStatus.setText("");
	}

	public void addVareTilOrdre()
	{
		for(int i = 0; i < oCtr.getVareList().size(); i++)
		{
			if((boolean)table.getModel().getValueAt(i, table.getModel().getColumnCount() - 1))
			{
				oCtr.addVareTilOrdre(Integer.parseInt(lblNyOrdreNr.getText()), (int)table.getModel().getValueAt(i, 0), 1);
			}
		}
	}

	public void sletOrdre()
	{
		int ordreNr = Integer.parseInt(lblNyOrdreNr.getText());
		oCtr.removeOrdre(oCtr.findKundeOrdreNr(ordreNr).getTlf(), ordreNr);
		oCtr.deleteOrdre(ordreNr);
		txtOrdreNr.setText("");
		bFindOrdre.doClick();
	}

	public void loadOrdre()
	{
		try
		{
			oCtr.load();
		}
		catch(ClassNotFoundException e)
		{
			System.out.println("Der skete en fejl under indl√¶sning af ordre");
		}
		catch(IOException e)
		{
			System.out.println("Der skete en fejl under indl√¶sning af ordre");
		}
		oCtr.ordreNoCounterCheck();
	}

	public void save()
	{
		try
		{
			oCtr.save();
		}
		catch(IOException e)
		{
			System.out.println("Filen kunne ikke gemmes");
		}
		System.out.println("Filen er gemt");
	}
}
